<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui"
	xmlns:c="http://java.sun.com/jsp/jstl/core"
	xmlns:composite="http://java.sun.com/jsf/composite"
	xmlns:pitang="http://pitang.com/jsf/custom-taglib">

<composite:interface>
	<composite:attribute name="editavel" default="true"/>
	<composite:attribute name="valor" required="true"/>
	<composite:attribute name="titulo"/>
	<composite:attribute name="mascara"/>
	<composite:attribute name="obrigatorio" default="true"/>
	<composite:attribute name="utilizarValidator" required="true"/>
	<composite:attribute name="maxlength" default="20"/>
	<composite:attribute name="size" default="20"/>
	<composite:attribute name="style"/>
	<composite:attribute name="label" required="true"/>
	<composite:attribute name="readonly" default="false" />
	<composite:editableValueHolder name="validator" targets="#{cc.id}_InputMask" />
	<composite:editableValueHolder name="conversor" targets="#{cc.id}_InputMask #{cc.id}_Label" />
	<composite:clientBehavior name="onblur" event="blur" targets="#{cc.id}_InputMask" />
</composite:interface>

<composite:implementation>

	<h:outputText id="#{cc.id}_Label" value="#{cc.attrs.valor}" converter="#{mascaraConverter}" 
		rendered="#{not cc.attrs.editavel}" style="font-weight:normal;"/>

	<p:inputText id="#{cc.id}_InputMask" onkeypress="if(#{cc.attrs.readonly}){return false;}"
				 title="#{cc.attrs.titulo}"  maxlength="#{cc.attrs.maxlength}" size="#{cc.attrs.size}" style="#{cc.attrs.style}" 
				 value="#{cc.attrs.valor}" rendered="#{cc.attrs.editavel}" required="#{cc.attrs.obrigatorio}" 
				 converter="#{MascaraConverter}" autocomplete="off" label="#{cc.attrs.label}">
			
			<f:validator validatorId="MascaraValidator" disabled="#{not cc.attrs.utilizarValidator}"/>		 
					 
	</p:inputText>
		
	<script>
		$(document).ready(function(){
			var mask = "#{cc.attrs.mascara}";
			if (mask){
				$('input[id="#{cc.clientId}:#{cc.id}_InputMask"]').each(function(){
					$(this).mask(mask);
				});
			}
		});
	</script>
	
	<script>
		function enter_pressed(e) {
			var code = (e.keyCode ? e.keyCode : e.which);
			if (code == 13) {
				$('input[id*="#{cc.id}_InputMask"]').blur();
			}
			return true;
		}
	</script>
		
</composite:implementation>
</html>